<?php

require('php/function/common.php');
require('php/function/general.php');

$ctrl = getPost('ctrl');
$func = getPost('func');
$team = getPost('team', 'manager');

if (empty($ctrl) || empty($func)) {
	$result = util::getVisitError('该服务已关闭！');
	echo convertJson($result);
}
else {
	$path = 'php/controller/' . $team . '/' . $ctrl . '.php';
	if (file_exists($path)) {
		date_default_timezone_set('PRC');

		require('php/config/domain.php');
		require('php/config/constant.php');
		require('php/config/database.php');
		require('php/function/sqlcon.php');
		require('php/function/intercept.php');

		$handle = new intercept();
		$result = $handle->preHandle($team, $ctrl, $func);
		if ($result != null) {
			echo convertJson($result);
		}
		else {
			require($path);
			$controller = new $ctrl;
			$result = $controller->$func();

			$result = $handle->nextHandle($team, $ctrl, $func, $result);

			echo convertJson($result);
		}
	}
	else {
		$result = util::getVisitError('系统错误！');
		echo convertJson($result);
	}
}